import serviceIo from '@/apis/request';
import urls, { PostModule, PostUrl } from './urls';
// 这里引入 urls 里的 默认抛出对象 postModules  还有按需引入 PostModule, PostUrl

// export class PostUrl {
// constructor(public name: string, public url: string, public type: string) { 
// }
// }
// export class PostModule {
//     constructor(public moduleName: string, public baseUrl: string, public urls: Array<PostUrl>) {
//     }
// }
const post: any = {};

//urls=[
// {baseUrl: "",moduleName: "common",urls[
//      {name: "getBaseDataList",type: "get",url: "/iccsrv/sys/dictdetail/dictSelect"}
// ]}


// ] 


// 遍历urls文件中所有模版
urls.forEach((module: PostModule) => {
    // // post.user={}
    post[module.moduleName] = {};
    // {name,url,type}
    // {name: "login", url: "/nebula/sys/login", type: "post"},
    module.urls.forEach((url: PostUrl) => {
        // 生成异步请求方法
        // @ts-ignore
        // post.user.
        post[module.moduleName][url.name] = (data: any) => serviceIo({
            url: url.url,
            // 默认所有方法都是post请求
            method: url.type,
            data
        });

    });
});

export default post;
